import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * taxRate.js - 税率定义 model
 * @date: 2018-10-29
 */
import { getResponse, createPagination } from 'utils/utils';
import { queryTaxRate as _queryTaxRate, updateTaxRate, insertTaxRate, queryTaxRateDetail as _queryTaxRateDetail, queryTaxRateInfo as _queryTaxRateInfo } from "../services/taxRateService";
export default {
  namespace: 'taxRate',
  state: {
    list: {},
    // 税率定义列表
    pagination: {} // 分页参数

  },
  effects: {
    // 查询平台级税率定义
    queryTaxRate: /*#__PURE__*/_regeneratorRuntime.mark(function queryTaxRate(_ref, _ref2) {
      var payload, call, put, res, list, pagination;
      return _regeneratorRuntime.wrap(function queryTaxRate$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.next = 4;
              return call(_queryTaxRate, payload);

            case 4:
              res = _context.sent;
              list = getResponse(res);
              pagination = createPagination(list);
              _context.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  list: list,
                  pagination: pagination
                }
              });

            case 9:
            case "end":
              return _context.stop();
          }
        }
      }, queryTaxRate);
    }),
    // 新增或更新平台级税率定义
    saveTaxRate: /*#__PURE__*/_regeneratorRuntime.mark(function saveTaxRate(_ref3, _ref4) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function saveTaxRate$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;

              if (!payload.taxId) {
                _context2.next = 8;
                break;
              }

              _context2.next = 5;
              return call(updateTaxRate, payload);

            case 5:
              res = _context2.sent;
              _context2.next = 11;
              break;

            case 8:
              _context2.next = 10;
              return call(insertTaxRate, payload);

            case 10:
              res = _context2.sent;

            case 11:
              return _context2.abrupt("return", getResponse(res));

            case 12:
            case "end":
              return _context2.stop();
          }
        }
      }, saveTaxRate);
    }),
    // 查询税率定义明细
    queryTaxRateDetail: /*#__PURE__*/_regeneratorRuntime.mark(function queryTaxRateDetail(_ref5, _ref6) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function queryTaxRateDetail$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call;
              _context3.next = 4;
              return call(_queryTaxRateDetail, payload);

            case 4:
              res = _context3.sent;
              return _context3.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context3.stop();
          }
        }
      }, queryTaxRateDetail);
    }),
    // 查询税率定义信息
    queryTaxRateInfo: /*#__PURE__*/_regeneratorRuntime.mark(function queryTaxRateInfo(_ref7, _ref8) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function queryTaxRateInfo$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call;
              _context4.next = 4;
              return call(_queryTaxRateInfo, payload);

            case 4:
              res = _context4.sent;
              return _context4.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, queryTaxRateInfo);
    })
  },
  reducers: {
    updateState: function updateState(state, action) {
      return _objectSpread(_objectSpread({}, state), action.payload);
    }
  }
};